﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace DotNetNuke.Modules.ActiveForums.Controls
    <DefaultProperty("Text"), ToolboxData("<{0}:TopicsNavigator runat=server></{0}:TopicsNavigator>")> _
    Public Class TopicsNavigator
        Inherits ForumBase
        Private _itemTemplate As DisplayTemplate

        Public Property ItemTemplate() As DisplayTemplate
            Get
                Return _itemTemplate
            End Get
            Set(ByVal Value As DisplayTemplate)
                _itemTemplate = Value
            End Set
        End Property
        Private _headerTemplate As DisplayTemplate
        Public Property HeaderTemplate() As DisplayTemplate
            Get
                Return _headerTemplate
            End Get
            Set(ByVal Value As DisplayTemplate)
                _headerTemplate = Value
            End Set
        End Property
        Private _footerTemplate As DisplayTemplate
        Public Property FooterTemplate() As DisplayTemplate
            Get
                Return _footerTemplate
            End Get
            Set(ByVal Value As DisplayTemplate)
                _footerTemplate = Value
            End Set
        End Property
        Public Property MaintainPage() As Boolean = False
        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            Dim tb As New Controls.TopicBrowser

            tb.PortalId = PortalId
            tb.ModuleId = ForumModuleId
            tb.TabId = ForumTabId
            If tb.TabId <= 0 Then
                tb.TabId = Integer.Parse(Request.QueryString("TabID"))
            End If
            tb.ForumGroupId = ForumGroupId
            tb.ForumId = ForumId

            If ForumId > 0 Then
                If Permissions.HasAccess(ForumInfo.Security.View, ForumUser.UserRoles) Then
                    tb.ForumIds = ForumId.ToString
                Else
                    writer.Write(String.Empty)
                    Exit Sub
                End If
            Else
                tb.ForumIds = UserForumsList
            End If
            If Not Request.QueryString("atg") Is Nothing AndAlso IsNumeric(Request.QueryString("atg")) Then
                tb.TagId = Integer.Parse(Request.QueryString("atg"))

            End If
            If Not Request.QueryString("act") Is Nothing AndAlso IsNumeric(Request.QueryString("act")) Then
                tb.CategoryId = Integer.Parse(Request.QueryString("act"))
            End If
            tb.ForumUser = ForumUser
            tb.PageIndex = PageId
            tb.PageSize = MainSettings.PageSize
            tb.Template = ItemTemplate.Text
            tb.HeaderTemplate = HeaderTemplate.Text
            tb.FooterTemplate = FooterTemplate.Text
            tb.ImagePath = Page.ResolveUrl("~/DesktopModules/ActiveForums/themes/" & MainSettings.Theme)
            tb.TopicId = TopicId
            tb.TimeZoneOffset = TimeZoneOffset
            writer.Write(tb.Render())
        End Sub

    End Class

End Namespace
